﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;


namespace AttributesExercises
{
    [Version("1")]
    class AttributesExample
    {
        static void Main(string[] args)
        {
            Type type = typeof(AttributesExample);
            object[] allAttributes = type.GetCustomAttributes(false);
            VersionAttribute version = (VersionAttribute)allAttributes[0];
            Console.WriteLine("This method is version: {0}", version.Name);
            
            Type typeVersionInAction = typeof(VersionsInAction);
            foreach (MethodInfo method in typeVersionInAction.GetMethods())
            {
                if (method.Name == "ToString" || method.Name == "GetHashCode" ||
                    method.Name == "GetType" || method.Name == "Equals")
                {
                    continue;
                }
                Console.WriteLine();
                object[] customAttributes = method.GetCustomAttributes(false);
                if (customAttributes.Count<Object>() > 0)
                {
                    Console.WriteLine("The Method {0} has the following version info: ", method.Name);
                }
                else
                {
                    Console.WriteLine("The Method {0} doesn't have any version info.", method.Name);
                }
                foreach (object objectAttribute in method.GetCustomAttributes(false))
                {
                    VersionAttribute versionAttribute = objectAttribute as VersionAttribute;
                    if (versionAttribute != null)
                    {
                        Console.WriteLine("Version Name: {0}", versionAttribute.Name);
                        if (versionAttribute.Comment != null)
                        {
                            Console.WriteLine("Version Comment: {0}", versionAttribute.Comment);
                        }
                    }
                }
            }
        }
    }
}